import mongoose from "mongoose";
import config from '../helpper/config';

const env = process.env.NODE_ENV;
const url = `${config[env]?.mongo_host}:${config[env]?.mongo_port}`
mongoose.connect(url,function(err){
    if(err){
        console.log('mongo connect error!')
    }
})
//获取connection实例
const db = mongoose.connection;
db.on('disconnected',function(err){
    console.log('disconnected')
});
db.on('connecting',function(err){
    console.log('connecting')
});
db.on('connected',function(err){
    console.log('connected')
});
db.on('open',function(err){
    console.log('open')
});
db.on('close',function(err){
    console.log('close')
});
db.on('reconnected',function(err){
    console.log('reconnected')
});
//同回调函数
db.on('error',function(err){
    console.log('--------error')
});

export default mongoose